<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#FFFFFF"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text" @click="down">我的星球</view>
    </view>
    <view class="tabs_box">
      <u-tabs
        class="tabs"
        :list="list1"
        @click="tabClick"
        :activeStyle="{
          color: '#eee',
          fontWeight: 'bold',
          transform: 'scale(1.05)',
          'font-size': '34rpx',
        }"
        lineColor="#eee"
        :inactiveStyle="{
          color: '#ADADAD',
          transform: 'scale(1)',
          'font-size': '34rpx',
        }"
        lineWidth="72rpx"
        lineHeight="4rpx"
      ></u-tabs>
    </view>
    <scroll-view
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
      @scrolltolower="scrolltolower"
    >
      <template>
        <view class="box" v-if="current == 0">
          <u-tabs
            :list="list4"
            lineWidth="0"
            lineColor="#f56c6c"
            :activeStyle="{
              color: '#EEEEEE',
              width: '144rpx',
              height: '56rpx',
              'line-height': '56rpx',
              'text-align': 'center',
              background: 'rgba(39,39,39,0.5)',
              'border-radius': '32rpx 32rpx 32rpx 32rpx',
              'font-size': '28rpx',
            }"
            :inactiveStyle="{
              width: '144rpx',
              height: '56rpx',
              'line-height': '56rpx',
              'text-align': 'center',
              background: 'rgba(39,39,39,0.5)',
              'border-radius': '32rpx 32rpx 32rpx 32rpx',
              color: '#ADADAD',
              'font-size': '28rpx',
            }"
            itemStyle="padding:0 20rpx; height: 56rpx'width: 144rpx"
            @change="change4"
            style="margin-top: 20rpx"
          >
          </u-tabs>
          <starList :isWhite="true" :list="gonglist"></starList>
        </view>
        <view class="box" v-if="current == 1">
          <starList
            :isWhite="true"
            type="myJoin"
            :list="jiaRulist"
            @updateDataJiaRu="updateDataJiaRu"
          ></starList>
        </view>
        <view class="box" v-if="current == 2">
          <starList
            :isWhite="true"
            type="myFollow"
            :list="guanzhulist"
            @updateDataQuGuan="updateDataQuGuan"
          ></starList>
        </view>
        <view
          class="box"
          v-if="current == 3"
          style="padding: 0 30rpx; box-sizing: border-box"
        >
          <star
            :showTitle="false"
            :whiteColor="true"
            :list="huifulist.data"
          ></star>
        </view>
        <view class="box" v-if="current == 4">
          <starList
            :isWhite="true"
            type="myRelease"
            :list="fabulist"
            @updateDataList="updateDataList"
          ></starList>
        </view>
      </template>
    </scroll-view>


    <floatingBall></floatingBall>
  </view>
</template>

<script>
import starList from "@/components/starList.vue"; //星河
import star from "@/components/search_co/star.vue"; //星河
export default {
  components: {
    starList,
    star,
  },
  data() {
    return {
      statusBarHeight: 0,
      height: 0,

      list1: [
        {
          name: "公共研讨",
        },
        {
          name: "我加入的",
        },
        {
          name: "我关注的",
        },
        {
          name: "我回复的",
        },
        {
          name: "我发布的",
        },
      ],
      list4: [
        {
          name: "心愿田",
        },
        {
          name: "贡献田",
        },
        {
          name: "善师田",
        },
      ],
      scrollHeihgt: 0,
      current: 0,
      currentIndex: 0,
      itemList: [{}, {}],
      gonglist: {},
      jiaRulist: {},
      guanzhulist: {},
      huifulist: {},
      fabulist: {},
      page: 1,
      last_page: 0,
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tabs_box").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum;
      });
    });

    //    this.getGongGong(1);
    //    this.getJiaRu();
    // this.getGuanZhu()
    // this.getHuiFu()
    // this.getFaBu()
  },
  onLoad() {
    this.getGongGong(1);
    // this.getJiaRu();
    // this.getGuanZhu();
    // this.getHuiFu();
    // this.getFaBu();
  },
  methods: {
    scroll() {},
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
        //  this.getList()
        if (this.current == 0) {
          this.getGongGong(1);
          if (this.currentIndex == 0) {
            this.getGongGong(1);
          } else if (this.currentIndex == 1) {
            this.getGongGong(2);
          } else {
            this.getGongGong(3);
          }
        } else if (this.current == 1) {
          this.getJiaRu();
        } else if (this.current == 2) {
          this.getGuanZhu();
        } else if (this.current == 3) {
          this.getHuiFu();
        } else if (this.current == 4) {
          this.getFaBu();
        }
      }
      console.log("触发");
    },
    change4(e) {
      this.page = 1;
      this.last_page = 0;
      this.currentIndex = e.index;
      if (e.index == 0) {
        this.getGongGong(1);
      } else if (e.index == 1) {
        this.getGongGong(2);
      } else {
        this.getGongGong(3);
      }
    },
    tabClick(e) {
      this.page = 1;
      this.last_page = 0;
      this.current = e.index;
      if (e.index == 0) {
        this.getGongGong(1);
      } else if (e.index == 1) {
        this.getJiaRu();
      } else if (e.index == 2) {
        this.getGuanZhu();
      } else if (e.index == 3) {
        this.getHuiFu();
      } else if (e.index == 4) {
        this.getFaBu();
      }
    },

    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },

    getGongGong(num) {
      this.$http
        .usergongnengGongGong({ type: num, page: this.page })
        .then((res) => {
          console.log(res.data.list, "心愿组");
          // this.gonglist = res.data.list;
          if (res.data.list.current_page == 1) {
            this.gonglist = res.data.list;
          } else {
            this.gonglist.data = this.gonglist.data.concat(res.data.list.data);
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    getJiaRu() {
      this.$http
        .usergongnengJiaRu({ page: this.page })
        .then((res) => {
          console.log(res.data.list, "我加入的");
          // this.jiaRulist = res.data.list;
          if (res.data.list.current_page == 1) {
            this.jiaRulist = res.data.list;
          } else {
            this.jiaRulist.data = this.jiaRulist.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    getGuanZhu() {
      this.$http
        .usergongnengGuanZhu({ page: this.page })
        .then((res) => {
          console.log(res.data.list, "我关注的");
          // this.guanzhulist = res.data.list;
          if (res.data.list.current_page == 1) {
            this.guanzhulist = res.data.list;
          } else {
            this.guanzhulist.data = this.guanzhulist.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    getHuiFu() {
      this.$http
        .usergongnengHuiFu({ page: this.page })
        .then((res) => {
          console.log(res.data.list, "我回复的");
          // this.huifulist = res.data.list;
          if (res.data.list.current_page == 1) {
            this.huifulist = res.data.list;
          } else {
            this.huifulist.data = this.huifulist.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    getFaBu() {
      this.$http
        .usergongnengFaBu({ page: this.page })
        .then((res) => {
          console.log(res.data.list, "我发布的");
          // this.fabulist = res.data.list;
          if (res.data.list.current_page == 1) {
            this.fabulist = res.data.list;
          } else {
            this.fabulist.data = this.fabulist.data.concat(res.data.list.data);
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    updateDataJiaRu() {
      this.getJiaRu();
    },
    updateDataQuGuan() {
      this.getGuanZhu();
    },
    updateDataList() {
      this.getFaBu();
    },
  },
};
</script>

<style scoped lang="scss">
.content {
  position: fixed;
  box-sizing: border-box;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
}

.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    font-size: 30rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    color: #55b877;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #ffffff;
  }
}
.box {
  // padding-top: 32rpx;
  box-sizing: border-box;
}
</style>